require(['../../common'], function() {
  require(['cate.addcate'])
})

define('cate.addcate', [
  'jquery',
  'css!ke/themes/default/default.css',
  'ke/kindeditor',
  'ke/lang/zh_CN',
  'jqp/validate'
], function($) {
  'use strict';

  var $form = $('#J_form')
  var $editor = $('#editor_id')
  var editor
  if ($editor.length) {
    editor = KindEditor.create($editor[0], {
      width: '70%',
      allowFileManager: true,
      uploadJson: APP + "?app=cms&m=Cate&a=uploadPic",
      fileManagerJson: APP + "?app=cms&m=Cate&a=getServerPic",
      fullscreenShortcut: true, //ESC快捷键控制编辑器全屏
      langType: 'zh_CN',
      resizeType: 2,
      allowPreviewEmoticons: false,
      allowImageUpload: false,
      items: [
        'source', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
        '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
        '|', 'emoticons', 'image', 'multiimage', 'flash', 'media', 'insertfile',
        'link', 'unlink', '|', 'fullscreen'
      ]
    })
    KindEditor('#image').click(function() {
      editor.loadPlugin('image', function() {
        editor.plugin.imageDialog({
          hiddenSizeAlignTitle: false,
          imageUrl: KindEditor('#imageurl').val(),
          clickFn: function(url, title, width, height, border, align) {
            KindEditor('#imageurl').val(url);
            editor.hideDialog();
          }
        });
      });
    });
  }

  $form.validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
      'cname': {
        required: '栏目名称不能为空'
      }
    }
  })
})
